package cn.rongdao.jrkabao.ui.main.mainfragment.adapter;

import android.support.v4.content.ContextCompat;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.TextView;

import com.mifengkong.frtools.ui.adapter.recyclerview.FRBaseRecyclerViewHolder;
import com.mifengkong.frtools.util.FRCollection;
import com.mifengkong.frtools.util.FRString;

import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.bean.main.vip.VipPurchaseRecordBean;

/**
 * Created by jack on 2018/1/26
 */

public class VipPurchaseRecordViewHolder extends FRBaseRecyclerViewHolder<VipPurchaseRecordBean> {

    private TextView tvTitle;
    private TextView tvContent;

    public VipPurchaseRecordViewHolder(View view) {
        super(view);
        tvTitle = findView(R.id.ivpr_tv_title);
        tvContent = findView(R.id.ivpr_tv_content);
    }

    @Override
    protected void onItemDataUpdated(VipPurchaseRecordBean vipPurchaseRecordBean) {
        setContent(vipPurchaseRecordBean.getPrice(), vipPurchaseRecordBean.getDesc());
        setTitle(vipPurchaseRecordBean.getTitle(), vipPurchaseRecordBean.getTime());
    }

    public void setContent(String price, String desc) {
        if (FRString.isEmpty(price, desc)) {
            return;
        }
        String content = FRCollection.appendAsString(price, "\n", desc, "");
        SpannableString ss = new SpannableString(content);
        ss.setSpan(new AbsoluteSizeSpan(12, true), price.length(), content.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        tvContent.setText(ss);
    }

    private void setTitle(String title, String payTime) {
        if (FRString.isEmpty(title, payTime)) {
            return;
        }
        String content = FRCollection.appendAsString(title, "\n", payTime, "");
        SpannableString ss = new SpannableString(content);
        ss.setSpan(new AbsoluteSizeSpan(11, true), title.length(), content.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        ss.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.c999999)), title.length(), content.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        tvTitle.setText(ss);
    }
}